package com.xw.bo.ks.util;

import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author： XW -> ~
 * @create： 2023/12/13 11:37
 */
public class BoCollectionUtil {


    /**
     * 将list转换为map
     * @param list 集合
     * @param keyMapper map的key
     * @return map对象
     */
    public static <T, K> Map<K, T> getMapToList(List<T> list, Function<? super T, ? extends K> keyMapper) {
        if (CollectionUtils.isEmpty(list)) {
            return new HashMap<>();
        }
        return list.stream().collect(Collectors.toMap(keyMapper, dto -> dto, (t1, t2) -> t1));
    }

    public static boolean isNotEmpty(Collection<?> collection){
        return !CollectionUtils.isEmpty(collection);
    }

    public static boolean isNotEmpty(Map<?, ?> map){
        return !CollectionUtils.isEmpty(map);
    }

}
